import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/4/18 10:49
 */

public class Solution {
    public int minCostClimbingStairs(int[] cost) {
        int n = cost.length;
        int[] dp = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int len = in.nextInt();
            int[] cost = new int[len];
            for (int i = 0; i < len; i++) {
                cost[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.minCostClimbingStairs(cost));
        }
    }
}